package com.qf.service.caiwu_service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.bean.Debt;
import com.qf.bean.PrefundRule;
import com.qf.dao.caiwu_dao.PrefundRuleMapper;
import com.qf.service.caiwu_service.PrefundRuleService;
import com.qf.utils.caiwu.enums.PrefundRuleStateEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 2019/12/11 0011
 * Author->DT
 * sassspringboot
 * 行到水穷处 坐看云起时
 * 模块：
 */
@Service
public class PrefundRuleServiceImpl implements PrefundRuleService {
    @Resource
    private PrefundRuleMapper prefundRuleMapper;

    //查询所有预存款规则信息
    @Override
    public List<PrefundRule> findAll() {
        return prefundRuleMapper.findAll();
    }

    @Override
    public PageInfo<PrefundRule> findPrefundRuleListByLimit(Map map) {
        //开启分页
        PageHelper.startPage((int)map.get("index"),(int)map.get("page"));
        //查询欠款信息列表
        List<PrefundRule> list=prefundRuleMapper.findDeptList(map);
        //封装PageInfo
        return new PageInfo<>(list);
    }

    //执行单行删除
    @Override
    public int deleteByPrimaryKey(Integer rid) {
        return prefundRuleMapper.deleteByPrimaryKey(rid);
    }

    @Override
    public int insertSelective(PrefundRule record) {
        //设置总额
        record.setTotalFund(record.getPrefund()+record.getGiveFund());
        //设置状态
        record.setState(PrefundRuleStateEnum.BEFORE.getState());
        //保存
        return prefundRuleMapper.insertSelective(record);
    }

    @Override
    public PrefundRule selectByPrimaryKey(Integer rid) {
        return prefundRuleMapper.selectByPrimaryKey(rid);
    }

    @Override
    public int updateByPrimaryKeySelective(PrefundRule record) {
        return prefundRuleMapper.updateByPrimaryKeySelective(record);
    }
}
